package ch.hslu.hs12.dmg;

import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateCounter {

	String today = null;
	
	public DateCounter(String aStartDate){
		today = aStartDate;
	}

	public void setDate(String aDate){
		today = aDate;
	}
	
	public String getDate(){
		return today;
	}

	public void incCurrentDate(){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar c = Calendar.getInstance();
			c.setTime(sdf.parse(today));
			c.add(Calendar.DATE, 1);
		} catch (ParseException e) {
			System.out.println("Error while incrementing a date");
			e.printStackTrace();
		}
	}
	
	
	public void decCurrentDate(){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar c = Calendar.getInstance();
			c.setTime(sdf.parse(today));
			c.add(Calendar.DATE, -1);
		} catch (ParseException e) {
			System.out.println("Error while incrementing a date");
			e.printStackTrace();
		}
	}
	
	
	public String incSpecificDate(String aDate){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar c = Calendar.getInstance();
			c.setTime(sdf.parse(aDate));
			c.add(Calendar.DATE, 1);
			return sdf.format(c.getTime());
		} catch (ParseException e) {
			System.out.println("Error while incrementing a date");
			e.printStackTrace();
			return "error";
		}

	}
	
	public String decSpecificDate(String aDate){
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar c = Calendar.getInstance();
			c.setTime(sdf.parse(aDate));
			c.add(Calendar.DATE, -1);
			return sdf.format(c.getTime());
		} catch (ParseException e) {
			System.out.println("Error while incrementing a date");
			e.printStackTrace();
			return "error";
		}

	}
	
	
}
